﻿namespace Chain.BLL
{
    using Chain.DAL;
    using Chain.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;

    public class SysShopMemLevel
    {
        private readonly Chain.DAL.SysShopMemLevel dal = new Chain.DAL.SysShopMemLevel();

        public int Add(Chain.Model.SysShopMemLevel model)
        {
            return this.dal.Add(model);
        }

        public List<Chain.Model.SysShopMemLevel> DataTableToList(DataTable dt)
        {
            List<Chain.Model.SysShopMemLevel> list = new List<Chain.Model.SysShopMemLevel>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.SysShopMemLevel item = new Chain.Model.SysShopMemLevel();
                    if ((dt.Rows[i]["ShopMemLevelID"] != null) && (dt.Rows[i]["ShopMemLevelID"].ToString() != ""))
                    {
                        item.ShopMemLevelID = int.Parse(dt.Rows[i]["ShopMemLevelID"].ToString());
                    }
                    if ((dt.Rows[i]["ShopID"] != null) && (dt.Rows[i]["ShopID"].ToString() != ""))
                    {
                        item.ShopID = int.Parse(dt.Rows[i]["ShopID"].ToString());
                    }
                    if ((dt.Rows[i]["MemLevelID"] != null) && (dt.Rows[i]["MemLevelID"].ToString() != ""))
                    {
                        item.MemLevelID = int.Parse(dt.Rows[i]["MemLevelID"].ToString());
                    }
                    if ((dt.Rows[i]["ClassDiscountPercent"] != null) && (dt.Rows[i]["ClassDiscountPercent"].ToString() != ""))
                    {
                        item.ClassDiscountPercent = decimal.Parse(dt.Rows[i]["ClassDiscountPercent"].ToString());
                    }
                    if ((dt.Rows[i]["ClassPointPercent"] != null) && (dt.Rows[i]["ClassPointPercent"].ToString() != ""))
                    {
                        item.ClassPointPercent = decimal.Parse(dt.Rows[i]["ClassPointPercent"].ToString());
                    }
                    if ((dt.Rows[i]["ClassRechargePointRate"] != null) && (dt.Rows[i]["ClassRechargePointRate"].ToString() != ""))
                    {
                        item.ClassRechargePointRate = int.Parse(dt.Rows[i]["ClassRechargePointRate"].ToString());
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int ShopMemLevelID)
        {
            return this.dal.Delete(ShopMemLevelID);
        }

        public bool DeleteByMemLevelID(int MemLevelID)
        {
            return this.dal.DeleteByMemLevelID(MemLevelID);
        }

        public bool DeleteList(string ShopMemLevelIDlist)
        {
            return this.dal.DeleteList(ShopMemLevelIDlist);
        }

        public bool Exists(int ShopMemLevelID)
        {
            return this.dal.Exists(ShopMemLevelID);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public int GetMaxId()
        {
            return this.dal.GetMaxId();
        }

        public Chain.Model.SysShopMemLevel GetModel(int ShopMemLevelID)
        {
            return this.dal.GetModel(ShopMemLevelID);
        }

        public Chain.Model.SysShopMemLevel GetModel(int MemLevelID, int shopID)
        {
            return this.dal.GetModel(MemLevelID, shopID);
        }

        public List<Chain.Model.SysShopMemLevel> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public int GetRechargePointRate(int memLevelID, int shopID)
        {
            return this.dal.GetRechargePointRate(memLevelID, shopID);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public bool Update(Chain.Model.SysShopMemLevel model)
        {
            return this.dal.Update(model);
        }
    }
}

